Imports System.SerializableAttribute
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.IO
Imports System.Xml

<Serializable()> _
Public Class VField
    Inherits AttributeBase

    Private mlViewID As Long
    Private mlViewRevID As Long
    Private mlColID As Long
    Private msName As String
    Private msDesc As String
    Private msType As String
    Private miSize As Integer
    Private miScale As Integer
    Private miPrecision As Integer
    Private miOrder As Integer

    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub New(ByVal lID As Long)
        MyBase.New(lID)
    End Sub

#Region "Properties"
    Public Property ColID() As Long
        Get
            Return mlColID
        End Get
        Set(ByVal value As Long)
            mlColID = value
        End Set
    End Property

    Public Property ViewID() As Long
        Get
            Return mlViewID
        End Get
        Set(ByVal value As Long)
            mlViewID = value
        End Set
    End Property

    Public Property ViewRevID() As Long
        Get
            Return mlViewRevID
        End Get
        Set(ByVal value As Long)
            mlViewRevID = value
        End Set
    End Property

    Public Property Name() As String
        Get
            Return msName
        End Get
        Set(ByVal value As String)
            msName = value
        End Set
    End Property

    Public Property Desc() As String
        Get
            Return msDesc
        End Get
        Set(ByVal value As String)
            msDesc = value
        End Set
    End Property

    Public Property Type() As String
        Get
            Return msType
        End Get
        Set(ByVal value As String)
            msType = value
        End Set
    End Property

    Public Property Size() As Integer
        Get
            Return miSize
        End Get
        Set(ByVal value As Integer)
            miSize = value
        End Set
    End Property

    Public Property Scale() As Integer
        Get
            Return miScale
        End Get
        Set(ByVal value As Integer)
            miScale = value
        End Set
    End Property

    Public Property Precision() As Integer
        Get
            Return miPrecision
        End Get
        Set(ByVal value As Integer)
            miPrecision = value
        End Set
    End Property

    Public Property Order() As Integer
        Get
            Return miOrder
        End Get
        Set(ByVal value As Integer)
            miOrder = value
        End Set
    End Property
#End Region

#Region "database"
    Public Sub Load()
        Dim oObject As New DBVField

        oObject.Load(Me)
    End Sub

    Public Sub Save()
        Dim oObject As New DBVField

        If mbObjectExists = True Then
            oObject.Update(Me)
        Else
            Me.CreateDate = Now
            oObject.Add(Me)
            mbObjectExists = True
        End If
    End Sub

    Public Sub Delete()
        Dim oObject As New DBVField

        oObject.Delete(Me)
        mbObjectExists = False
    End Sub
#End Region

    Public Function SerializeMe() As String
        Dim oMS As New MemoryStream
        Dim oSXML As New System.Xml.Serialization.XmlSerializer(GetType(SQLAutoDocLib.VField))
        oSXML.Serialize(oMS, Me)

        Dim oEncoding As System.Text.ASCIIEncoding = New System.Text.ASCIIEncoding
        Dim sXML As String = oEncoding.GetString(oMS.GetBuffer)

        Return sXML
    End Function
End Class
